package
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.ui.Keyboard;

	public class Boat extends Sprite
	{
		[Embed(source="../res/boat.png")]
        public var ImageBoat:Class;
		public var imageBoat:Bitmap;
		public var speed:int = 2;
		public var lost:Boolean = true;
		public var rot:int = 5;
		
		public var isZPressed:Boolean = false;
		public var isQPressed:Boolean = false;
		public var isDPressed:Boolean = false;
		
		/**
		 * Object : Boat
		 */
		public function Boat(){
			this.imageBoat = new ImageBoat();
			this.addChild(imageBoat);
			this.width = imageBoat.width;
			this.height = imageBoat.height;
			this.x = 0;
		}
		
		public function rotate(degree:int):void{
			this.imageBoat.rotation += degree;
		}
		
		public function move():void
		{
			this.speed += this.acceleration;
			if(this.speed > 10)
			{
				this.speed = 10
				this.acceleration = 0;
			}
			if(this.speed < 0)
			{
				this.speed = 0
				this.acceleration = 0;
			}
				
			if(isZPressed || this.speed > 0)
			{
				var radians:Number = this.imageBoat.rotation * Math.PI / 180;
				this.imageBoat.x += Math.cos(radians)*speed;
				this.imageBoat.y += Math.sin(radians)*speed;
			}
			
			if(isDPressed)
			{
				this.rotate(10);
			}
			
			if(isQPressed)
			{
				this.rotate(-10);
			}
		}
		
		public function keyPress(event:KeyboardEvent):void
		{
			if(event.keyCode == Keyboard.Z)
			{
				this.isZPressed = true;
			}
			
			if(event.keyCode == Keyboard.D)
			{
				this.isDPressed = true;
			}
			
			if(event.keyCode == Keyboard.Q)
			{
				this.isQPressed = true;
			}
		}
		
		public function keyRelease(event:KeyboardEvent):void
		{
			if(event.keyCode == Keyboard.Z)
			{
				this.isZPressed = false;
			}
			
			if(event.keyCode == Keyboard.D)
			{
				this.isDPressed = false;
			}
			
			if(event.keyCode == Keyboard.Q)
			{
				this.isQPressed = false;
			}
		}
	}	
}